<template>
	<view class="folderMove" :class="APPTheme">
		<uni-nav-bar fixed status-bar left-icon="back" :color="APPTheme=='theme-light'?'#000000':'#ffffff'" :background-color="APPTheme=='theme-light'?'#ffffff':'#000000'"
		 @clickLeft="$lizhao.lznavigate.lzNavigateBack()">
			<view slot="left">返回</view>
		</uni-nav-bar>
		<view class="center">
			<view class="theme-bg theme-bg-active" v-for="(item,index) in folder.list" :key="index">
				<uni-list>
					<!-- fileType 0为文件夹 
					roleType//0是管理者权限，1为上传/编辑权限，2为查看权限
					filingType 0为共享盘【只有共享盘才有权限控制roleType】
					-->
					<template v-if="item.filingType=='0'">
						<uni-list-item v-if="item.fileType==0&&item.filingCabinetsRole.roleType!='2'" @tap="navigateToFn(item)" thumb="/static/image/filemanag/wenjianja.png" :title="item.filingName" :note="item.fileSize?computeFileSize(item.fileSize):''"></uni-list-item>
					</template>
					<template v-else>
						<uni-list-item v-if="item.fileType==0" @tap="navigateToFn(item)" thumb="/static/image/filemanag/wenjianja.png" :title="item.filingName" :note="item.fileSize?computeFileSize(item.fileSize):''"></uni-list-item>
					</template>
					<uni-list-item v-if="item.fileType!=0" :thumb="computedFileType(item)" :title="item.filingName" :note="computeFileSize(item.fileSize)" style="opacity: 0.4;" :showArrow='false'></uni-list-item>
				</uni-list>
			</view>
			<u-empty text="暂无文件夹" class="u-empty" mode="data" v-if="folder.list.length==0" :margin-top="200"></u-empty>
		</view>
		<view class="footer theme-bg">
			<view class="f-left" @click="newFolderFn" v-if="transmission.menu.parentId!='-1'">新建文件夹</view>
			<view class="f-right" @click="MoveHere" :class="transmission.menu.parentId=='-1'?'prohibit':''">移动到这里</view>
		</view>
		
		<!-- 对话框 -->
		<uni-popup ref="dialogInput" type="dialog">
			<uni-popup-dialog mode="input" title="新建文件夹" placeholder="请输入新建文件夹命名" type="error" @confirm="dialogInputConfirm"></uni-popup-dialog>
		</uni-popup>
		<u-no-network></u-no-network>
	</view>
</template>

<script>
	let that
	import {
		mapGetters,
		mapActions
	} from 'vuex'
	import lzFolderList from '../components/folder-list/folder-list.vue'
	import uniPopupShare from '@/components/uni-popup/uni-popup-share.vue'
	import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue'
	export default {
		components: {
			lzFolderList,
			uniPopupShare,
			uniPopupDialog
		},
		data() {
			return {
				folder: {
					list: []
				},
				//传过来的值
				transmission: null
			}
		},
		computed: {
			...mapGetters(['APPTheme', 'userInfo', 'api']),
			//计算图片属性
			computedFileType() {
				return (item) => {
					return that.$lizhao.lzfile.lzGetFileType(item.suffix)
				}
			},
			//计算文件大小
			computeFileSize() {
				return (size) => {
					return that.$lizhao.lzfile.lzGetFileSize(size)
				}
			},
			
		},
		onLoad(e) {
			that = this
			that.transmission = JSON.parse(decodeURIComponent(e.option))
			//获取共享盘数据
			that.filingCabinets_list()
		},
		onShow() {
			that = this
			//获取当前页的传递参数（用于页面回退后还能获取当前页面参数）
			that.getCurrentPagesQuery()
			//设置主题颜色
			that.GLOBAL.setThemeColor(that.APPTheme)
		},
		
		methods: {
			//获取当前页的传递参数（用于页面回退后还能获取当前页面参数）
			getCurrentPagesQuery(){
				var pages = getCurrentPages();
				var page = pages[pages.length - 1];
				//#ifdef APP-PLUS
				let query=decodeURIComponent(page.$getAppWebview().getStyle().uniPageUrl.query)
				that.transmission=JSON.parse(query.split('=')[1])
				//#endif
				//#ifdef H5
				that.transmission=page.transmission
				//#endif
				console.log(that.transmission.menu.parentId);
				//获取共享盘数据
				that.filingCabinets_list()
			},
			//获取列表信息
			filingCabinets_list(){
				let req={
					boolPage:false,//是否分页
					parentId:that.transmission.menu.parentId,//当前文件夹id
					filingType:that.transmission.menu.filingType//0共享盘1私人盘2加密盘
				}
				let api
				if(that.transmission.menu.filingType==0){//共享盘
					api=that.api.GLOBAL_admin_rest_biz_filingCabinets_list
				}else{
					api=that.api.GLOBAL_admin_rest_biz_filingCabinets_searchPage
				}
				
				that.GLOBAL.doGet(api,req).then(res=>{
					if(res.code=='0'){
						that.folder.list=res.data
					}
				})
			},
			navigateToFn(item){
				item.parentId=item.id
				let req={
					menu:item,
					checkboxListId:that.transmission.checkboxListId//已选择的文件id
				}
				uni.navigateTo({
					url: '/pages/document/folderMove/folderMove?option='+encodeURIComponent(JSON.stringify(req)),
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			//点击移动到这里
			MoveHere(){
				//不能移动到根节点
				if(that.transmission.menu.parentId=='-1')return
				let req={
					filingId:that.transmission.menu.parentId,//文件夹id
					fileIds:that.transmission.checkboxListId.join(','),//文件数组id
				}
				that.GLOBAL.doGet(that.api.GLOBAL_admin_rest_biz_filingCabinets_moveFile,req).then(res=>{
					if(res.code=='0'){
						uni.showToast({
							title: res.data.msg,
							icon:"none"
						});
						//获取共享盘数据
						that.filingCabinets_list()
					}
				})
			},
			//新建文件夹
			newFolderFn(){
				that.$refs.dialogInput.open()
			},
			//确认新建文件夹
			dialogInputConfirm(fn,item){
				let req={
					fileType:0,//文件类型文件夹
					filingName:item,//文件柜名称
					filingType:that.transmission.menu.filingType,//文件柜类型
					parentId:that.transmission.menu.parentId,//文件夹id
				}
				that.GLOBAL.doPost(that.api.GLOBAL_admin_rest_biz_filingCabinets_save,req).then(res=>{
					that.$refs.dialogInput.close()
					if(res.code=='0'&&res.data.flag){
						uni.showToast({
							title: res.data.msg,
							icon:"success"
						});
						that.filingCabinets_list()
						//更新父级列表
						uni.$emit('folderMove_save',true)
					}else{
						uni.showToast({
							title: res.data.msg,
							icon:"none"
						});
					}
				})
			},
		}
	};
</script>

<style scoped lang="scss">
	.folderMove {
		height: 100%;
		.center{
			padding-bottom: 50px;
			.theme-bg{
				padding:0 10rpx;
			}
			
		}
		.footer{
			position: fixed;bottom: 0;width: 100%;display: flex;justify-content: space-between;padding: 10px 15px;box-sizing: border-box;
			.f-left{
				font-size: 16px;color: #5b5b88;
			}
			.f-right{
				padding: 5px 15px;border-radius: 15px;background-color: #007AFF;color: #fff;font-size: 12px;
			}
			.prohibit{color: #fff;background-color: #888;margin-left:70%;box-sizing: border-box;}
		}
		
	}
</style>
